import numpy as np
import matplotlib.pyplot as plt
#支持中文
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
# 支持负数
plt.rcParams['axes.unicode_minus'] = False
# 数据准备
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
categories = ['苹果', '香蕉', '橙子', '葡萄']
sales_2022 = [45, 30, 25, 40]
sizes = [15, 30, 45, 10]
labels = ['A', 'B', 'C', 'D']
# 创建更灵活的子图布局
fig, axd = plt.subplot_mosaic([
    ['line', 'scatter'],
    ['bar', 'pie']
], figsize=(10, 8))


axd['line'].plot(x, y)
axd['scatter'].scatter(x, y)
axd['bar'].bar(categories, sales_2022)
axd['pie'].pie(sizes, labels=labels)


plt.tight_layout()
plt.show()
